package com.yowasa.xiuxian.engine.battle.strategy.drop.all;

import cn.hutool.core.util.RandomUtil;
import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.constant.XiuxianConstants;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.BuffContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Map;

@BS(name = "魔阴身")
@Order(501)
@Component
public class MoYinShen extends BaseSpellStrategy {
    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return ElementEnum.SOIL;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {

        double shield = first.getBattleInfo().getSpell() * 0.3 + first.getBattleInfo().getRes();
        first.getFlag().put("魔阴身",(int)shield);

        BuffContent buff = new BuffContent();
        buff.setNum(3);
        buff.setDuration(10);
        first.getBuff().put("噬魔", buff);

        int costMp = first.getBattleInfo().getRes() / 2;
        first.getBattleInfo().setCmp(first.getBattleInfo().getCmp() - costMp);
        first.getCd().put("魔阴身", 5);
    }

    @Override
    public void limit(UserBO user) {
        if (user.getStage() < 4) {
            throw new HandlerException("学习/使用魔阴身阶位需要在了彻之白以上");
        }
        if (user.getElement().get("土") < XiuxianConstants.DEFAULT_ELEMENT_ACTIVITY) {
            throw new HandlerException("学习/使用魔阴身必须具有土灵根");
        }
    }

    @Override
    public String limitDesc() {
        return "学习/使用魔阴身阶位需要在了彻之白以上，且拥有土灵根";
    }

    @Override
    public String desc() {
        return "消耗法抗一半的mp，生成一个法攻0.3+防抗1.0的护盾,cd 5,护盾值不可叠加，新护盾会顶替旧护盾,当护盾存在时，每回合流失6%hp（不致死）,并提升20%法攻";
    }

    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        Integer cd = user.getCd().get("魔阴身");
        if (cd != null && cd > 0) {
            return false;
        }
        int costMp = user.getBattleInfo().getRes() / 2;
        if (user.getBattleInfo().getCmp() < costMp) {
            return false;
        }
        return true;
    }
}
